<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested" %>

<%@ page import="hibernate.dao.PersonneDAO" %>
<%@ page import="hibernate.dao.PieceJustificativeDAO" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="hibernate.Personne" %> 
<%@ page import="hibernate.PieceJustificative" %> 

<html:html>
<head>
<title>Struts File Upload Example</title>
<!-- <html:base/> -->
<style type="text/css">@import url(css/style.css);</style>
</head>
<body bgcolor="white">
<div id="header">
				<!--  <div class="left"><img src="logo_SUAPS.jpg"></div>
				<div class="right"><h1>S.U.A.P.S.</h1><br>
				<h3>SERVICE UNIVERSITAIRE DES ACTIVITES PHYSIQUES ET SPORTIVES</h3></div>-->
				<div class="left"><a href="./index.jsp"><img src="./css/body.png" width="100%" ></a></div>
				<ul id="nav">
				
						<li><a href="./AfficherCreationPersonne.do">Inscription</a></li>
						<li><a href="#">Sports & Horaires</a></li>
						<li><a href="#">Formation</a></li>
						<li><a href="#">Sant&eacute;</a></li>
						<li><a href="#">Actus et animations</a></li>
						<li><a href="#">Stages et tournois</a></li>
				</ul>
</div>
<html:form action="/FileUpload.do" method="post" enctype="multipart/form-data">
<table>
<tr>
<td align="center" colspan="2">
<font size="4">Please Enter the Following Details</font>
</tr>

<tr>
<td align="left" colspan="2">
<font color="red"><html:errors/></font>
</tr>





<% 
			int idPersonne=(Integer) session.getAttribute("idPersonne");
			//int idPersonne=1;
			//out.println(idPersonne);
			PersonneDAO lDAO = new PersonneDAO();
			Personne p = lDAO.findPersonneDAO(idPersonne);
			//out.println(p.getIdType().getIdType());
			
			PieceJustificativeDAO pDAO = new PieceJustificativeDAO();
			List<PieceJustificative> l = pDAO.listPieceJustificativeDAO(p.getIdType().getIdType());
			int i=0;
			ArrayList<PieceJustificative> pieces = new ArrayList<PieceJustificative>();
			for(PieceJustificative piece : l){ 
				pieces.add(piece);
				i++;
			}
			
			//out.println("test");
%>

<% if (i == 1){ %>
<tr>
<td align="right">
<%= pieces.get(0).getNomPiece() %>
</td>
<html:hidden property="idType1" value="<%= pieces.get(0).getIdPiece().toString() %>" />
<td align="left">
<html:file property="theFile1"/>
</td>
</tr>
<% } %>
<% if (i == 2){ %>
<tr>
<td>
<%= pieces.get(0).getNomPiece() %>
</td>
<html:hidden property="idType1" value="<%= pieces.get(0).getIdPiece().toString() %>" />
<td>
<html:file property="theFile1"/>
</td>
</tr>
<tr>
<td>
<%= pieces.get(1).getNomPiece() %>
</td>
<html:hidden property="idType2" value="<%= pieces.get(1).getIdPiece().toString() %>" />
<td>
<html:file property="theFile2"/>
</td>
</tr>
<% } %>

<html:hidden property="nbDocs" value="<%=Integer.toString(i) %>"/>

<tr>
<td align="center" colspan="2">
<html:submit>Upload fichiers</html:submit>
</td>
</tr>
</table>


</html:form>

<jsp:include page="/footer.html"></jsp:include>

</body>
</html:html>